<?php
// +----------------------------------------------------------------------
// | ManniuRead
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://manniuyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: heitao <read@manniuyun.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use manniu\controller\AdminBase;

use app\admin\model\LinkageData as LinkageDataModel;
use app\admin\model\Linkage as LinkageModel;

class LinkageData extends AdminBase{

    //当前控制器菜单
    public $submenu = [];
	/**
	 * TP初始化方法
	 */
	public function _initialize(){
		parent::_initialize();
        $this->submenu[] = ['title' => '联动菜单列表', 'url' => url('admin/linkage/index'), 'icon' => '&#xe60a;'];
	}

    /**
     * 联动菜单列表
     * @access public
     * @return \think\Response
     */
    public function index($linkage_id = 0, $pid = 0){
        $linkage_id = (int)$linkage_id;
        $pid = (int)$pid;
        if(!$linkage_id){
            $this->error('缺少联动菜单分类id','admin/linkage/index');
        }
        $parent = LinkageDataModel::get(['id'=>$pid]);
        $linkage = LinkageModel::get(['id'=>$linkage_id]);
        $list = LinkageDataModel::all(['pid'=> $pid,'linkage_id'=>$linkage_id]);
        $this->assign([
            'submenu'   => $this->submenu,
            'list'      => $list,
            'parent'    => $parent,
            'linkage'   => $linkage
        ]);
        return $this->fetch();
    }
}